ASSERT() on calls to Tokenizer::tokenize() in test code#3501
ASSERT() on calls to Tokenizer::tokenize() in test code#3501danmar merged 26 commits intocppcheck-opensource:mainfrom
Conversation
|
And how about this one? ;) |
| LOAD_LIB_2(settings.library, "std.cfg"); | ||
| std::istringstream istr(code); | ||
| tokenizer.tokenize(istr, "test.cpp"); | ||
| ASSERT(tokenizer.tokenize(istr, "test.cpp")); |
There was a problem hiding this comment.
The idea is pretty good. We want to fail if this fails. Unfortunately the output will not make much sense. Can we do something alternative that will make the output somewhat more helpful if this fails.
There was a problem hiding this comment.
Hmm, like a macro ASSERT_TOKENIZE() that adds something to errout on failure? Or what do you have in mind?
There was a problem hiding this comment.
I don't think ASSERT_TOKENIZE will work neither it would point out the line where the tokenize fails right? So you have no idea where check is called from.
How about:
if (!tokenizer.tokenize(istr, "test.cpp))
errout << "tokenize failed!";
So execution will continue and when errout is checked there will be an assertion error that is more clear.
An alternative could be to change check() so it takes a line number and then we can print the line number in the error message.
#define check(code) check_(code, __LINE__)
void check_(const char code[], int line)
.....
There was a problem hiding this comment.
What I want is that if the test case at line 654 calls check() directly or indirectly. Then I want that the assertion message says that the test case at line 654 fails. I fear that it will complain about line 53 with your suggestion where the tokenizer.tokenize() is called. And then you have to manually debug to figure out where the problem is.
There was a problem hiding this comment.
That would require numerous changes, since every test defines its own check()-like functions... Could be done though.
There was a problem hiding this comment.
That would require numerous changes, since every test defines its own check()-like functions... Could be done though.
could you try it out on 1 check function to start with so we see that it looks reasonable.
There was a problem hiding this comment.
I have added something to test64bit.cpp
| Tokenizer tokenizer(&settings, this); | ||
| std::istringstream istr(code); | ||
| tokenizer.tokenize(istr, "test.cpp"); | ||
| ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; |
There was a problem hiding this comment.
That looks some search and replace bug - there's more of that.
There was a problem hiding this comment.
ASSERT needs to return something here, Maybe that's not the way it's supposed to be used though...
| Tokenizer tokenizer(&settings, this); | ||
| std::istringstream istr(code); | ||
| tokenizer.tokenize(istr, "test.cpp"); | ||
| ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; |
There was a problem hiding this comment.
That looks some search and replace bug - there's more of that.
danmar
left a comment
There was a problem hiding this comment.
Nice! It looks promising
|
|
||
| #define TEST_CASE( NAME ) do { if (prepareTest(#NAME)) { setVerbose(false); NAME(); } } while (false) | ||
| #define ASSERT( CONDITION ) if (!assert_(__FILE__, __LINE__, (CONDITION))) return | ||
| #define ASSERT_LOC( CONDITION ) if (!assert_(file, line, (CONDITION))) return |
There was a problem hiding this comment.
I would prefer that the macro takes the file,line as arguments so the interface is clear.
I don't think a return here will help much, the test will continue to run. Probably a very misleading assertion failure would follow. I suggest that the return is removed and the test will continue as before.
|
There is quite a number of |
maybe we can merge it step by step. If you clean this up I would not mind to merge it. |
good 👍 |
| Tokenizer tokenizer(&settings, this); | ||
| std::istringstream istr(code); | ||
| tokenizer.tokenize(istr, "test.cpp"); | ||
| ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; |
There was a problem hiding this comment.
before I merge I want that this is fixed.
There was a problem hiding this comment.
Ok, there is still a lot to do yet. You could also push this separately: fa69d3c
|
I think I'm more or less done now. Feel free to merge anything you like... |
No description provided.